package javabase.schoolwork.day6_12;

import org.junit.Test;

import java.util.*;

/**
 * @author fance
 * @date 18-6-11 下午3:03
 */
public class ListSum {
    public void fun1() {
        List<String> stringList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            stringList.add(String.valueOf(i));
        }
        for (String s : stringList) {
            System.out.print(s + " ");
        }
    }
    public void fun2() {
        List<String> stringList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            stringList.add(String.valueOf(i));
        }

        String[] arr =  stringList.toArray(new String[] {});
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i] + " ");
        }

        Object[] objectArr = stringList.toArray();
        for (int i = 0; i < objectArr.length; i++) {
            System.out.println(objectArr[i] + " ");
        }
    }
    public void fun3() {
        List<String> stringList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            stringList.add(String.valueOf(i));
        }

        System.out.println(stringList.contains("9"));
        System.out.println(stringList.contains("900"));

        List<String> list = stringList.subList(2,4);
        for (String s : list) {
            System.out.print(s + " ");
        }
        System.out.println();

        System.out.println(stringList.indexOf("3"));
        System.out.println(stringList.isEmpty());
    }
    public void fun4() {
        LinkedList<String> queue = new LinkedList<>();
        for (int i = 0; i < 10; i++) {
            queue.offer(String.valueOf(i));
        }

        for (String s : queue) {
            System.out.print(s + " ");
        }

    }
    public void fun5() {
        List<String> queue = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            queue.add(String.valueOf(i));
        }

        Iterator<String> iterator = queue.iterator();
        while (iterator.hasNext()) {
            String i =  iterator.next();
            if (i.equals("1")) {
                iterator.remove();
            } else {
                System.out.print(i + " ");
            }
        }
//        iterator.remove();

    }
    public void fun6() {
        List<String> queue = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            queue.add(String.valueOf(i));
        }

        ListIterator<String> iterator = queue.listIterator();
        while (iterator.hasNext()) {
            String i =  iterator.next();
            if (i.equals("1")) {
                iterator.remove();
            } else {
                System.out.print(i + " ");
            }
        }
        while (iterator.hasPrevious()) {
            String i =  iterator.previous();
            if (i.equals("1")) {
                iterator.remove();
            } else {
                System.out.print(i + " ");
            }
        }


    }

    public void fun7() {
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            list1.add(i);
            list2.add(i * 2);
        }
        list1.addAll( list2);
        System.out.println(list1);

        Collections.reverse(list1);
        System.out.println(list1);

        System.out.println(Collections.binarySearch(list1,2));

        list1.indexOf(2);

        list1.set(0,100);

        Collections.sort(list1);

       Collections.swap(list1,0,1);
        System.out.println(list1);
    }

    @Test
    public void test() {
        // fun1();
//        fun2();
//        fun3();
//        fun4();
//        fun5();
//        fun6();
        fun7();
    }
}
